package org.yaukie.support;

import java.lang.annotation.Annotation;
import java.util.List;
import org.yaukie.support.api.ClassSupportApi;
import org.yaukie.support.base.AnnotationByBaseClass;
import org.yaukie.support.base.BaseClass;
import org.yaukie.support.base.SuperByBaseClass;

public class ClassSupportImpl implements ClassSupportApi {
    public ClassSupportImpl() {
    }

    public List<Class<?>> getClassList(String packageName) {
        return (new BaseClass(packageName) {
            public boolean checkAddClass(Class<?> cls) {
                String className = cls.getName();
                String pkgName = className.substring(0, className.lastIndexOf("."));
                return pkgName.startsWith(this.packageName);
            }
        }).getClassList();
    }

    public List<Class<?>> getClassListByAnnotation(String packageName, Class<? extends Annotation> annotationClass) {
        return (new AnnotationByBaseClass(packageName, annotationClass) {
            public boolean checkAddClass(Class<?> cls) {
                return cls.isAnnotationPresent((Class<? extends Annotation>) this.annotationClass);
            }
        }).getClassList();
    }

    public List<Class<?>> getClassListBySuper(String packageName, Class<?> superClass) {
        return (new SuperByBaseClass(packageName, superClass) {
            public boolean checkAddClass(Class<?> cls) {
                return this.superClass.isAssignableFrom(cls) && !cls.equals(this.superClass);
            }
        }).getClassList();
    }
}